<?php
include("../inc/db_connect.php");
include("../inc/functions.php");
$nac_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '".$_POST['zid']."' AND date='".$_POST['date']."' ";
$nac_q = MySQL_Query ($nac_s);
$nac = MySQL_Fetch_Array ($nac_q);
if (isset($nac['id'])) {
    if (($_POST['value']=='IN')||($_POST['value']=='MOD')) {
        $uloz_u = "UPDATE dochadzkazamfalk SET planOd='00:00',planDo='08:00',realOd='00:00',realDo='08:00',type = '".$_POST['value']."' WHERE zid = '".$_POST['zid']."' AND date='".$_POST['date']."' ";
        $uloz_q = MySQL_Query ($uloz_u);
    } elseif ($_POST['value']=='SPL') {
        $uloz_u = "UPDATE dochadzkazamfalk SET type = '".$_POST['value']."' WHERE zid = '".$_POST['zid']."' AND date='".$_POST['date']."' ";
        $uloz_q = MySQL_Query ($uloz_u);
    } else {
        $uloz_u = "UPDATE dochadzkazamfalk SET planOd='',planDo='',realOd='',realDo='',splitOd='',splitDo='',type = '".$_POST['value']."' WHERE zid = '".$_POST['zid']."' AND date='".$_POST['date']."' ";
        $uloz_q = MySQL_Query ($uloz_u);
    }
} else {
    $d = date('j',$_POST['date']);
    $m = date('n',$_POST['date']);
    $y = date('Y',$_POST['date']);
    $sv_s = "SELECT id FROM sviatok WHERE den = '".$d."' AND mesiac='".$m."' AND rok='".$y."' ";
    $sv_q = MySQL_Query ($sv_s);
    $sv = MySQL_Fetch_Array ($sv_q);
    if (isset($sv['id'])) {
        $sviatok = $sv['id'];
    } else {
        $sviatok = 0;
    }
    $uloz_i = "INSERT INTO dochadzkazamfalk (id, zid, date, type, sviatok) VALUES (NULL, '".$_POST['zid']."', '".$_POST['date']."', '".$_POST['value']."', '".$sviatok."')";
    $uloz_q = MySQL_Query ($uloz_i);
}
?>
